<?php

error_reporting(E_ALL);

/**
 * ECommerce - class.ControladorUsuario.php
 *
 * $Id$
 *
 * This file is part of ECommerce.
 *
 * Automatically generated on 17.11.2011, 16:09:48 with ArgoUML PHP module 
 * (last revised $Date: 2010-01-12 20:14:42 +0100 (Tue, 12 Jan 2010) $)
 *
 * @author firstname and lastname of author, <author@example.org>
 */

if (0 > version_compare(PHP_VERSION, '5')) {
    die('This file was generated for PHP 5');
}

/* user defined includes */
// section -84-27-7--68-30076843:133b28e8ad6:-8000:0000000000000CF8-includes begin
require_once('class.VistaUsuario.php');
require_once('class.ModeloUsuario.php');
require_once('class.Usuario.php');
// section -84-27-7--68-30076843:133b28e8ad6:-8000:0000000000000CF8-includes end

/* user defined constants */
// section -84-27-7--68-30076843:133b28e8ad6:-8000:0000000000000CF8-constants begin
// section -84-27-7--68-30076843:133b28e8ad6:-8000:0000000000000CF8-constants end

/**
 * Short description of class ControladorUsuario
 *
 * @access public
 * @author firstname and lastname of author, <author@example.org>
 */
class ControladorUsuario
{
    // --- ASSOCIATIONS ---


    // --- ATTRIBUTES ---

    /**
     * Short description of attribute miVistaUsuario
     *
     * @access public
     * @var VistaUsuario
     */
    public $miVistaUsuario = null;

    /**
     * Short description of attribute miModeloUsuario
     *
     * @access public
     * @var ModeloUsuario
     */
    public $miModeloUsuario = null;

    /**
     * Short description of attribute usuario
     *
     * @access public
     * @var Usuario
     */
    public $usuario = null;

    // --- OPERATIONS ---

    /**
     * Short description of method Lista
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return void
     */
    public function Lista()
    {
        // section -84-27-7--68-30076843:133b28e8ad6:-8000:0000000000000CFF begin
        $datos=$this->miModeloUsuario->getAllRows();		
		$this->miVistaUsuario->Lista($datos);	
        // section -84-27-7--68-30076843:133b28e8ad6:-8000:0000000000000CFF end
    }

    /**
     * Short description of method Alta
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return void
     */
    public function Alta()
    {
        // section -84-27-7--68-30076843:133b28e8ad6:-8000:0000000000000D01 begin
                if (@$_REQUEST[Aceptar]) {
				$this->miModeloUsuario->insertRow($_REQUEST);
				$this->Lista();
				}
			else
				$this->miVistaUsuario->Alta();
        // section -84-27-7--68-30076843:133b28e8ad6:-8000:0000000000000D01 end
    }

    /**
     * Short description of method Editar
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return void
     */
    public function Editar()
    {
        // section -84-27-7--68-30076843:133b28e8ad6:-8000:0000000000000D03 begin
        if (@$_REQUEST[Aceptar]) {								// Boton Aceptar
				$this->miModeloUsuario->updateRow(@$_REQUEST);		// Graba en el modelo
				$this->Lista();									// Muestra la lista
			}
			else {	
					$datos = $this->miModeloUsuario->searchById(@$_REQUEST[id]);
					$this->miVistaUsuario->Edicion($datos);
			}	
        // section -84-27-7--68-30076843:133b28e8ad6:-8000:0000000000000D03 end
    }

    /**
     * Short description of method Borrar
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return void
     */
    public function Borrar()
    {
        // section -84-27-7--68-30076843:133b28e8ad6:-8000:0000000000000D05 begin
        if (@$_REQUEST[Aceptar]) {
				$this->miModeloUsuario->deleteRow(@$_REQUEST[id]);
				$this->Lista();
			}
			else {	
				$datos = $this->miModeloUsuario->searchById(@$_REQUEST[id]);
				$this->miVistaUsuario->borrar($datos);
			}	
        // section -84-27-7--68-30076843:133b28e8ad6:-8000:0000000000000D05 end
    }

    /**
     * Short description of method Controlador
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return void
     */
    public function ControladorUsuario()
    {
        // section -84-27-7--68-30076843:133b28e8ad6:-8000:0000000000000D07 begin
        $this->miModeloUsuario = new ModeloUsuario();		
		$this->miVistaUsuario = new VistaUsuario();	
        //var_dump($_REQUEST);
		// VISTA 
		if(@$_REQUEST["controlador"]=="listaUsuario" || @$_REQUEST[Cancelar]) 		// Boton generico cancelar
		{
			$this->Lista();
		}
		else 
		{
			if(@$_REQUEST["controlador"]=="buscarUsuario") 	
				$this->Buscar();
			if(@$_REQUEST["controlador"]=="nuevoUsuario")
				$this->Alta();			
			if(@$_REQUEST["controlador"]=="editarUsuario")
				$this->Editar();
			if(@$_REQUEST["controlador"]=="borrarUsuario") 
				$this->Borrar();
			if(@$_REQUEST["controlador"]=="login") 
				$this->Login();
			if(@$_REQUEST["controlador"]=="logout") 
				$this->Logout();
			if(@$_REQUEST["controlador"]=="iniciar") 
				$this->Iniciar();
		}
        // section -84-27-7--68-30076843:133b28e8ad6:-8000:0000000000000D07 end
    }

    /**
     * Short description of method Buscar
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return void
     */
    public function Buscar()
    {
        // section -84-27-7--68-30076843:133b28e8ad6:-8000:0000000000000D09 begin
     //  $this->miVistaUsuario->Login();
        $datos=$this->miModeloUsuario->getRowsByNombre($_REQUEST["nombre"]);		
		$this->miVistaUsuario->Lista($datos);
        // section -84-27-7--68-30076843:133b28e8ad6:-8000:0000000000000D09 end
    }
    
    public function Login()
    {
        // section -84-27-7--68-30076843:133b28e8ad6:-8000:0000000000000D09 begin
       $this->miVistaUsuario->Login();
        // section -84-27-7--68-30076843:133b28e8ad6:-8000:0000000000000D09 end
    }
    
    public function Logout()
    {
        // section -84-27-7--68-30076843:133b28e8ad6:-8000:0000000000000D09 begin
        $this->usuario = new Usuario();
        $this->usuario->logout();  
        // section -84-27-7--68-30076843:133b28e8ad6:-8000:0000000000000D09 end
    }
    
    public function Iniciar()
    {
       $this->usuario = new Usuario();
       $this->usuario->checkUsuario();        
        if (@$_REQUEST[user] && @$_REQUEST[pass]) 
        { 	// Valida request
        	//echo @$_REQUEST[user];
        	$this->usuario->login(@$_REQUEST[user],@$_REQUEST[pass]);     	
        	if ($this->usuario->isLogged()) 
        	{
        		if($this->usuario->isAdmin())
        		{
        			if (@$_SESSION["userRow"]["Rol"] == "Administrador")
        			{
        				echo "<br><br><a href='index.php?controlador=reporteVendidos'>Activar el menu del Administrador</a>";
        			}
        			//$_SESSION['user'] = "Admin"; 
        			//echo "Admin";
        		} 
        		else
        		{
        		    //$_SESSION['user'] = "User";
        		    //echo "User";
        		}
        	}
        	else
        	{
        		//$_SESSION['user'] = "Desconocido";
        		//echo "Desconocido";
        	}     		
        }
    }
} /* end of class ControladorUsuario */
?>